package org.apache.ocean;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.jdom.Element;

/**
 *
 * @author  jason rutherglen
 */
public class UpdateResponse implements CElement {
	public static final String SUCCESS = "success";
	public static final String ERROR = "error";
  public String status;
  public String errorMessage;
  public OceanDocument oceanDocument;
  public CLong duration;
  public String batchID;
  
  public UpdateResponse() {}
  
  public String toString() {
  	return ReflectionToStringBuilder.toString(this);
  }
  
  public UpdateResponse(Element element) throws Exception {
  	status = XMLUtil.getChildText("status", element);
  	duration = XMLUtil.getChildLong("duration", element);
  	errorMessage = XMLUtil.getChildText("errorMessage", element);
  	Element documentElement = element.getChild("document");
  	if (documentElement != null) {
  		oceanDocument = new OceanDocument(documentElement);
  	}
  }
  
  public Element toElement() throws Exception {
  	Element root = new Element("updateResponse");
  	XMLUtil.createTextElement("status", status, root);
  	XMLUtil.createTextElement("errorMessage", errorMessage, root);
  	if (oceanDocument != null) root.addContent(oceanDocument.toElement());
  	XMLUtil.createTextElement("duration", duration, root);
  	return root;
  }
}
